package com.moyq5.spring.boot.app.register.server;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * APP状态查询任务
 * @author Moyq5
 * @date 2019年3月7日
 */
@Component
public class AppInfoCheckTask {
	
	private static final Logger log = LoggerFactory.getLogger(AppInfoCheckTask.class);
	private static boolean isDoing = false;
	private static int times = 0;
	
	@Autowired
	private AppInfoExecutor executor;
	
	@Scheduled(cron = "0/10 * * * * ? ")
	public synchronized void scheduled() {
		times++;
		if (isDoing) {
			log.debug("有APP查询任务在执行，忽略本次任务：{}", times);
			return;
		}
		
		isDoing = true;
		log.debug("第{}次APP查询任务>>>>>>>>>", times);
		try {
			executor.checkAndNoticeAll();
		} catch(Exception e) {
			log.error("第{}次APP查询任务异常：", e);
		} finally {
			isDoing = false;
		}
	}
	
}
